﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhsystem.Main;
using dhSystemBLL.produceBLL;
using baseSet.importExport;

namespace dhsystem.produceForm.Stock
{
    public partial class FrmproductStock : Form
    {
        productStockBLL productStock = new productStockBLL();
       // string state;
        public FrmproductStock()
        {
            InitializeComponent();
        }
        //打开窗口时显示列表数据
        private void FrmproductStock_Load(object sender, EventArgs e)
        {
            bindingSourceproductStock.DataSource = productStock.getV_productStockAll ();
            dGridproductStock.DataSource = bindingSourceproductStock;
            DcolumnSet.colSet(moduleInfo.V_productStock, dGridproductStock);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridproductStock.RowCount.ToString() + "条";
        }
        //新增按钮，显示新增窗口
        private void toolAdd_Click(object sender, EventArgs e)
        {
            //state = "新增";
            //FrmproductStockAdd productStockAdd = new FrmproductStockAdd(bindingSourceproductStock, state);
            //productStockAdd.ShowDialog();
        }
        //工具栏查询按钮，查询所有列表数据
        private void toolQuery_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.productStock);
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridproductStock.DataSource = query.rTable;
            }
        }
        //工具栏的编辑按钮,修改数据
        private void toolEdit_Click(object sender, EventArgs e)
        {
            //state = "编辑";
            //FrmproductStockAdd productStockAdd = new FrmproductStockAdd(bindingSourceproductStock, state);
            //productStockAdd.ShowDialog();
        }
        //删除按钮，删除选中行数据
        private void toolDel_Click(object sender, EventArgs e)
        {
            //string produceNo = dGridproductStock.Rows[dGridproductStock.CurrentRow.Index].Cells[0].Value.ToString();
            //try
            //{
            //    DialogResult result = MessageBox.Show("是否删除原材料：" + produceNo + "！", "提示信息", MessageBoxButtons.YesNo);
            //    if (result == DialogResult.Yes)
            //    {

            //        bindingSourceproductStock.DataSource = productStock.productStockDel(produceNo);
            //        dGridproductStock.DataSource = bindingSourceproductStock;
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message.ToString());
            //}
            //bindingSourceproductStock.DataSource = productStock.getproductStockAll();
        }
        //查询按钮，按条件查询数据
        private void buttonQuery_Click(object sender, EventArgs e)
        {
            try
            {
                baseSet.Query q = new baseSet.Query(null, dhDataAcess.baseBLL.dataConn.connOpen());
                bindingSourceproductStock.DataSource = q.sqlQueryLikeAll(moduleInfo.V_productStock, textorderDetailNoQuery.Text.ToString().Trim());
                dGridproductStock.DataSource = bindingSourceproductStock;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }

        }
        //刷新按钮
        private void buttupdate_Click(object sender, EventArgs e)
        {
            bindingSourceproductStock.DataSource = productStock.getproductStockAll();
            dGridproductStock.DataSource = bindingSourceproductStock;
            DcolumnSet.colSet(moduleInfo.productStock, dGridproductStock);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridproductStock.RowCount.ToString() + "条";
        }
        //工具栏退出按钮，退出窗口
        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //datagridview第一列显示行号
        private void dGridorderproductStock_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.productStock , dGridproductStock , "胚带库存信息");
            frm.ShowDialog();
        }
    }
}
